package com.mk.community.modules.bbs.controller;


import com.mk.community.common.api.CommonPage;
import com.mk.community.modules.bbs.dto.DiscussPostVo;
import com.mk.community.modules.bbs.service.DiscussPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 * 创建表记录：POST /{控制器路由名称}/create
 * 修改表记录：POST /{控制器路由名称}/update/{id}
 * 删除指定表记录：POST /{控制器路由名称}/delete/{id}
 * 分页查询表记录：GET /{控制器路由名称}/list
 * 获取指定记录详情：GET /{控制器路由名称}/{id}
 *
 * @author MagicKong
 * @since 2021-09-27
 */
@Api(tags = "帖子管理")
@Controller
@RequestMapping("/bbs/discussPost")
public class DiscussPostController {
    public static final Logger LOGGER = LoggerFactory.getLogger(DiscussPostController.class);

    @Autowired
    private DiscussPostService discussPostService;

    @ApiOperation("分页查询帖子列表")
    @GetMapping("/list")
    public String list(@RequestParam(name = "userId", required = false, defaultValue = "0") Integer userId,
                       @RequestParam(name = "current", required = false, defaultValue = "1") long current,
                       @RequestParam(name = "size", required = false, defaultValue = "10") long size,
                       HttpServletRequest request,
                       Model model) {
        LOGGER.debug("start -> 分页查询帖子列表");
        CommonPage<DiscussPostVo> discussList = discussPostService.listDiscussPost(userId, current, size);
        discussList.setPath(request.getServletPath());
        model.addAttribute("discussList", discussList);
        LOGGER.warn("test warn -> 测试警告级别日志输出");
        LOGGER.error("test error -> 测试错误级别日志输出");
        LOGGER.debug("end -> 分页查询帖子列表");
        return "index";
    }


}

